$(function(){
    //初始化页面列表
    $("#compensation_datagrid").datagrid({
        fit:true,
        url:"/compensation/listByCompensationForPay",
        fitColumns:true,
        striped:true,
        pagination:true,
        singleSelect:true,
        checkOnSelect:true,
        rownumbers:true,
        toolbar:"#tb",
        columns:[[
            {field:'id',title:'编号', hidden:true},
            {field:'checkbox',checkbox:true,tilte:'选中',width:100},
            {field:'state',title:'支付状态',align:'center',width:100,formatter:function(value){
                if(value==0){
                    return "<p style='color: red'>待审核</p>"
                }else if(value==1){
                    return "<p style='color: orange'>待支付</p>"
                }else if(value==2){
                    return "<p style='color: green'>支付成功</p>"
                }else{
                    return "<p style='color: deeppink'>支付失败</p>"
                }
            }},
            {field:'client.clientname',title:'投保人',align:'center',width:100,formatter:function(value,rows,index){
                if(rows.client!=null){
                    return rows.client.clientname;
                }else{
                    return "";
                }
            }},
            {field:'beneficiary',title:'受益人',align:'center',width:100},
            {field:'account',title:'账户',align:'center',width:100},
            {field:'amountpay',title:'赔偿金额',align:'center',width:100},
            {field:'insuranceNo',title:'保险单号',align:'center',width:100},
        ]]
    })
    //初始化页面列表--end

    //初始化案件详情弹窗
    $("#compensation_dialog").dialog({
        width:400,
        height:400,
        closed:true
    })
    //初始化案件详情弹窗--end

    //初始化理赔明细弹窗
    $("#claimBill_dialog").dialog({
        width:400,
        height:400,
        buttons:"#bb",
        closed:true
    })
    //初始化案件详情弹窗--end

    //初始化案件详情下拉表格
    $("#client_grid").combogrid({
        panelWidth:450,
        url:'/client/queryFormalClient',
        idField:'id',
        textField:'clientname',
        fit:true,
        fitColumns:true,
        striped:true,
        singleSelect:true,
        checkOnSelect:true,
        pagination:true,
        rownumbers:true,
        toolbar:"#accident_tb",
        columns:[[
            {field:'id',title:'客户编号',width:60,hidden:true},
            {field:'clientname',title:'客户姓名',width:100,align:'center'},
            {field:'gender',title:'性别',width:100,align:'center',formatter:function(value){
                if(value==1){
                    return "男";
                }else{
                    return "女";
                }
            }},
            {field:'tel',title:'练习方式',width:100,align:'center'},
            {field:'email',title:'邮箱',width:100,align:'center'},
            {field:'insuranceNo',title:'保险单号',width:100,align:'center'}
        ]]
    })
    //初始化案件详情下拉表格--end

})
//列表页面查看案情事件
function details(){
    var selectedRow = $("#compensation_datagrid").datagrid("getSelected");
    if(!selectedRow){
        $.messager.alert("温馨提示","请选择要查看的数据");
        return;
    }
    $("#compensation_dialog").dialog("setTitle","<p style='text-align: center;color:deepskyblue;font-size: 13px;line-height:8px'>查看案件详情</p>");
    $("#compensation_form").form("clear");
    $("#compensation_dialog").dialog("open");
    selectedRow["client.id"]=selectedRow.client.id;
    $.get("/accident/viewAccident?id="+selectedRow.client.id,function (data) {
        if(data){
            selectedRow["occurenceTime"]=data.occurenceTime;
            selectedRow["occurencePlace"]=data.occurencePlace;
            selectedRow["responsibility"]=data.responsibility;
            selectedRow["caseDescript"]=data.caseDescript;
            selectedRow["note"]=data.note;
            $("#compensation_form").form("load",selectedRow);
        }else{
            $.messager.alert("温馨提示","加载数据失败")
        }
    })
}
//列表页面查看案情事件--end

//刷新列表页面
function reload1(){
    $("#compensation_datagrid").datagrid("reload");
}
//刷新列表页面--end

//查询
function query() {
    var keyword = $("#keyword").textbox("getValue")
    $("#compensation_datagrid").datagrid("load",{
        keyword : keyword
    });
}
//查询 --end
//导出excel表格
function report() {
    $.messager.confirm('确认','您确认想要导出成excel表格文件吗？',function(r){
        if (r){
            $.get("/compensation/report",function (data) {
                if(data.success){
                    $.messager.alert("温馨提示","导出文件成功")
                }else{
                    $.messager.alert("温馨提示",data.msg)
                }
            })
        }
    });

}
//导出excel表格--end
